class Solution {
public:
    bool canPartition(vector<int>& nums) {
        if (nums.size() < 2) return false; 
        int target = 0;
        for (auto x : nums) target += x;
        if (target & 1) return false;
        target >>= 1;
        vector<int> dp(target + 1, 0);
        for (int i = 1; i < nums.size(); i++) {
            for (int j = target; j >= nums[i]; j--) {
                dp[j] = max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }
        return dp[target] == target;
    }
};
